package com.example.xinhuaxin.service.impl;

import com.example.xinhuaxin.dao.CardDao;
import com.example.xinhuaxin.entity.Card;
import com.example.xinhuaxin.service.CardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import java.util.UUID;


/**
 * @description:
 * @author: YancyZhang
 * @time: 2022/6/8 10:31
 */
@Service
public class CardServiceImpl implements CardService {
    @Autowired
    CardDao cardDao;

    public List<Card> getCardList(){

        return cardDao.getCardList();
    }

    public Card getCardInfo(int card_id){
        return cardDao.getCardInfo(card_id);
    }

    @Override
    public Boolean bindCard(String user_id, int card_id) {
        try {
            UUID uuid = UUID.randomUUID();
            String str = uuid.toString();
            cardDao.bindCard(str, user_id, card_id, 1);
            return true;
        }catch (Exception e){
            return false;
        }
    }

    public String getCardDetail(String userId, int cardId){return cardDao.getBindInfo(userId, cardId);}

    @Override
    public Boolean closeAccount(String bindId) {
        try{
            cardDao.closeAccount(bindId);
            return true;
        }catch (Exception e){
            return false;
        }
    }
}